package com.chinaunicom.order.infrastructure.gateway;

import com.chinaunicom.order.domain.gateway.IMarketingGateway;
import com.chinaunicom.order.domain.model.entity.CalculateOrderEntity;
import com.chinaunicom.order.domain.model.entity.OrderItemEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author guomenghuai
 * @date 2024/1/15
 * @Description
 */
@Slf4j
@Component
public class MarketingGateway implements IMarketingGateway {

    @Override
    public Integer calculateOrderAmount(CalculateOrderEntity calculateOrderEntity) {
        log.info("模拟营销服务计算订单金额。。。");
        List<OrderItemEntity> orderItemList = calculateOrderEntity.getOrderItemList();

        Integer orderAmount = 0;

        for (OrderItemEntity orderItemEntity : orderItemList) {
            orderAmount += orderItemEntity.getSalePrice() * orderItemEntity.getQuantity();
        }
        log.info("calculateOrderAmount 计算后金额为：{}", orderAmount);
        return orderAmount;
    }
}
